<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *售后列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'用户违纪'),
	array('op'=>'class','title'=>'导出违纪表'),
	array('op'=>'log','title'=>'违纪记录'),
);
$worker=pdo_get('jy_yxw_worker',array('id'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']));
$storeidlist=str_array($worker['storeidlist']);
if(!$storeidlist){
	$storeidlist=-1;
}
//售后列表
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$storeidlist);
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['classid']){
		$params['classid']=intval($_RQ['classid']);
		$return['params']['classid']=$_RQ['classid'];
	}
	if(!empty($_RQ['title'])){
		$params2=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
		$xueshengids=$this->getall('xuesheng',$params2,array('id','title'),'id');
		if($xueshengids){
			$xueshengids=array_keys($xueshengids);
		}else{
			$xueshengids=-1;
		}
		$params['xueshengid']=$xueshengids;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	$list=pdo_getslice('jy_yxw_xuesheng',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$day=date('Y-m-d',time());
		foreach($list as &$item){
			$item['member']=$this->model('xuesheng')->member_show($item['id']);
			$item['wj1']=pdo_count('jy_yxw_weiji_log',array('type'=>1,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
			$item['wj2']=pdo_count('jy_yxw_weiji_log',array('type'=>2,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
			$item['wj3']=pdo_count('jy_yxw_weiji_log',array('type'=>3,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','del_message'=>'确认删除该售后吗？','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'sn','title'=>'编号','type'=>'string'),
			array('name'=>'storeid','width'=>'15','title'=>'所属门店','type'=>'select2','options'=>'stores'),
			array('name'=>'classid','title'=>'售后群','type'=>'select2','options'=>'class'),
			array('type'=>'string','title'=>'普通违纪次数','name'=>'wj1'),
			array('type'=>'string','title'=>'中等违纪次数','name'=>'wj2'),
			array('type'=>'string','title'=>'严重违纪次数','name'=>'wj3'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'售后名称','name'=>'title','help'=>''),
			array('name'=>'classid','width'=>'15','title'=>'售后群','type'=>'select','options'=>'class'),
			array('name'=>'storeid','width'=>'15','title'=>'所属门店','type'=>'select','options'=>'stores'),
		),
	);
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['type']=$this->weiji_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='log'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$storeidlist);
	$return['params']['status']=$_RQ['status'];
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	$list=pdo_getslice('jy_yxw_weiji_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('xuesheng')->member_show($item['xueshengid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：
		</br>1、这里显示违纪资料！
		','del_message'=>'确认删除该违纪吗？','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'type','title'=>'违纪类型','type'=>'radio','options'=>'weiji_type'),
			array('type'=>'string','title'=>'违纪原因','name'=>'remark'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			//array('type'=>'model','op'=>'setstore','title'=>'修改门店'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'售后姓名','name'=>'title','help'=>''),
			array('name'=>'type','width'=>'15','title'=>'违纪类型','type'=>'radio','options'=>'weiji_type'),
		),
	);
	$return['workers']=$this->getall('worker',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));	
	$return['weiji_type']=$this->weiji_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='class'){
	$params=array('storeid'=>$storeidlist,'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
    $orderby='id desc';
	$total='';
	$return['list']=$this->getall('class',$params,array(),'',$orderby);
	foreach($return['list'] as &$item){
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：
		</br>这里显示本门店的售后群；
		','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'售后群名称','type'=>'string'),
			array('name'=>'workerid','title'=>'售后主管','type'=>'select2','options'=>'workers'),
			array('name'=>'kechengid','title'=>'绑定使用','type'=>'select2','options'=>'kechengs'),
			array('name'=>'keshi','title'=>'课时','type'=>'string'),
			array('name'=>'xueshengnum','title'=>'用户人数','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio2','options'=>'status'),
			array('name'=>'open_time','title'=>'开班时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'export','action'=>'/store.s_item.xuesheng.weiji/export/','title'=>'导出本月违纪'),
			array('type'=>'export','action'=>'/store.s_item.xuesheng.weiji/export1/','title'=>'导出上月违纪'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'售后群名称','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status'),
		),
	);
	//$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['workers']=$this->getall('worker',array('role'=>11,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['kechengs']=$this->getall('kecheng',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['status']=$this->class_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export' || $_RQ['op']=='export1'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$storeidlist);
	if($_RQ['id']){
		$params['classid']=intval($_RQ['id']);
	}else{
		exi('请选择售后群！','error');
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	$year =date('Y');
	$month =date('m');
	$monthtime=strtotime($year.'-'.$month);
	if($_RQ['op']=='export1'){
		$lasttime=strtotime('-1 month');
		$year =date('Y',$lasttime);
		$month =date('m',$lasttime);
		$tstart=strtotime($year.'-'.$month);
		$params['createtime between']=array($tstart,$monthtime);
	}else{
		$params['createtime >']=$monthtime;
	}
	$list=pdo_getall('jy_yxw_weiji_log',$params,$fields);
	if($list){
		foreach($list as &$item){
			$item['title']=pdo_getcolumn('jy_yxw_xuesheng',array('id'=>$item['xueshengid'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
		}
	}
	$header=array(
		'xueshengid'=>'售后ID',
		'title'=>'售后姓名',
		'remark'=>'违纪描述',
		'createtime'=>'违纪时间',
	);
	$classtitle=pdo_getcolumn('jy_yxw_class',array('id'=>$params['classid'],'uniacid'=>$_SESSION['uniacid']),'title');
	model('core/tools')->export2excel($header,$list,$classtitle.'['.$year . '-' . $month . ']违纪');
}